<!--一行显示按钮和搜索-->

<nz-spin [nzSpinning]="isSpinning">
  <div class="toolbar margin-bottom btn-and-search" [ngClass]="isMobile?'wrap-mobile':'wrap'">
    <div class="item" [ngClass]="isMobile?'item-mobile':''" nz-col nzXs="8" nzSm="8" nzMd="14" nzLg="14" nzXl="18">
      <button (click)="addAgency()" class="margin-right" nz-button
              nzType="primary">
        <i nz-icon nzType="plus" nzTheme="outline"></i>
        <span *ngIf="!isMobile">添加</span>
      </button>

      <button nz-button nzType="default" (click)="loadData()">
        <i nz-icon nzType="redo" nzTheme="outline"></i><span *ngIf="!isMobile">刷新</span>
      </button>
    </div>

    <div class="item" [ngClass]="isMobile?'item-mobile':''" nz-col nzXs="16" nzSm="16" nzMd="10" nzLg="10" nzXl="6">
      <nz-input-group nzSearch [nzAddOnAfter]="suffixIconButton">
        <input type="text" nz-input placeholder="合作伙伴名称/机构号/负责人/手机号" [(ngModel)]="pageHelper.keyword"/>
      </nz-input-group>
      <ng-template #suffixIconButton>
        <button nz-button nzType="primary" nzSearch><i nz-icon nzType="search" (click)="findListByKeyword()"></i>
        </button>
      </ng-template>
    </div>

  </div>

  <div [ngClass]="isMobile?'wrap-mobile':'wrap'">
    <nz-table #expandTable nzBordered [nzData]="listOfMapData" nzTableLayout="fixed"  [nzScroll]="{ x: 'auto' }">
      <thead>
      <tr>
        <th>合作伙伴名称</th>
        <th>机构号</th>
        <th>商户推广码</th>
        <th>地区</th>
        <th>管理账号</th>
        <th>负责人</th>
        <th>手机号</th>
        <th *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId || roleIdEnum.AGENT == userInfo.roleId">余额</th>
        <th *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId">所属机构</th>
        <th *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId">上级机构简称</th>
        <th>类型</th>
        <th>注册时间</th>
        <th nzRight>操作</th>
      </tr>
      </thead>
      <tbody>
      <ng-container *ngFor="let data of expandTable.data">
        <ng-container *ngFor="let item of mapOfExpandedData[data.key]">
          <tr *ngIf="(item.parent && item.parent.expand) || !item.parent">
            <td
                [nzIndentSize]="item.level! * 20"
                [nzShowExpand]="!!item.children"
                [(nzExpand)]="item.expand"
                (nzExpandChange)="baseService.zorro.collapse(mapOfExpandedData[data.key], item, $event)"
            >
              {{ item.agencyName }}
            </td>
            <td>{{ item.agencyNo }}</td>
            <td style="text-align: center" (click)="showQrCode(item)"><a><i nz-icon nzType="qrcode"></i></a></td>
            <td>{{ item.province + ' ' + item.city }}</td>
            <td>{{ item.username }}</td>
            <td>{{ item.name }}</td>
            <td>{{ item.mobile }}</td>
            <td
                *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId || roleIdEnum.AGENT == userInfo.roleId">{{ item.commissionBalance}}</td>
            <td *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId">{{ item.parentAgencyNo}}</td>
            <td *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId">{{ item.parentAlias}}</td>
            <td>
              <label *ngIf="item.type==1">个人</label>
              <label *ngIf="item.type==2">个体户</label>
              <label *ngIf="item.type==3">有限公司</label>
            </td>
            <td>{{ item.createTime | date: 'yyyy-MM-dd HH:mm:ss' }}</td>
            <td nzRight>
              <div>
                <a *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId" (click)="editAgency(item)">详情</a>
              </div>
              <div>
                <a *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId" (click)="configuration(item)">配置</a>
              </div>
              <div>
                <a nz-dropdown [nzDropdownMenu]="menu" *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId">
                  设置
                  <i nz-icon nzType="down"></i>
                </a>
                <nz-dropdown-menu #menu="nzDropdownMenu">
                  <ul nz-menu nzSelectable>
                    <li nz-menu-item>
                      <a *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId && item.userStatus != 4"
                         (click)="changeAgencyStatus(item,0)">冻结</a>
                      <a *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId && item.userStatus == 4"
                         (click)="changeAgencyStatus(item,1)">恢复</a>
                    </li>
                    <li nz-menu-item>
                      <a *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId"
                         (click)="resetPassword(item)">重置密码</a>
                    </li>
                    <li nz-menu-item>
                      <a *ngIf="roleIdEnum.SUPER_ADMINISTRATOR == userInfo.roleId" (click)="resetOperatePassword(item)">重置操作密码</a>
                    </li>
                  </ul>
                </nz-dropdown-menu>
              </div>
              <!--            <a>禁用</a>-->
              <!--            <a *ngIf="userInfo.roleId == roleIdEnum.SUPER_ADMINISTRATOR && (item.dockingStatus == 0 || item.dockingStatus == null)" (click)="updateDockingStatus(item)"> <i class="unfreeze" nz-icon nzType="check-circle" nzTheme="twotone" [nzTwotoneColor]="'#3ac569'" nz-tooltip-->
              <!--               nzTooltipTitle="开启对接模式" nzTooltipPlacement="bottom"></i>-->
              <!--            </a>-->
              <!--            <a *ngIf="userInfo.roleId == roleIdEnum.SUPER_ADMINISTRATOR && item.dockingStatus == 1" (click)="updateDockingStatus(item)">-->
              <!--              <i nz-icon nzType="close-circle" nzTheme="twotone" [nzTwotoneColor]="'#F5222D'" nz-tooltip-->
              <!--                 nzTooltipTitle="关闭对接模式" nzTooltipPlacement="bottom"></i>-->
              <!--            </a>-->
            </td>
          </tr>
        </ng-container>
      </ng-container>
      </tbody>
    </nz-table>
  </div>
</nz-spin>

<app-agency-configuration [isVisible]="isVisibleConfiguration" [item]="item"
                          (emit)="setConfiguration($event)"></app-agency-configuration>

<app-agency-edit [isVisible]="isVisible" [agencyInfoDetailVisible]="agencyInfoDetailVisible" [agencyId]="agencyId"
                 (emit)="setVisible($event)" (emit)="setAgencyInfoDetailVisible($event)"></app-agency-edit>

<app-code-info [isVisible]="qrCodeVisible" [qrCodeContent]="qrCodeContent" [fileName]="fileName"
               (emitVisible)="setQrCodeVisible($event)"></app-code-info>
